package com.sn.pw.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sn.pw.dao.entity.LogisticsInfo;
import com.sn.pw.dao.mapper.LogisticsInfoMapper;
import com.sn.pw.exception.ServiceException;
import com.sn.pw.service.LogisticsInfoService;
import com.sn.pw.vo.resp.LogisticsInfoResp;
import org.springframework.stereotype.Service;

import static com.sn.pw.code.impl.BaseErrorCode.SERVICE_ERROR;


@Service("logisticsInfoService")
public class LogisticsInfoServiceImpl extends ServiceImpl<LogisticsInfoMapper, LogisticsInfo> implements LogisticsInfoService {

    @Override
    public LogisticsInfoResp getLogisticsInfoByShippingOrderNumber(String shippingOrderNumber) {
        LambdaQueryWrapper<LogisticsInfo> lambdaQueryWrapper = Wrappers.<LogisticsInfo>lambdaQuery().eq(LogisticsInfo::getShippingOrderNumber, shippingOrderNumber);
        LogisticsInfo info = super.getOne(lambdaQueryWrapper);
        if (ObjectUtil.isEmpty(info)) {
            throw new ServiceException(SERVICE_ERROR);
        }
        return BeanUtil.toBean(info, LogisticsInfoResp.class);
    }
}
